package bairui.international.service.impl;

import bairui.international.model.domain.jpa.TB_Product;
import bairui.international.service.Service_Product_Generate;
import org.springframework.stereotype.Service;
import bairui.international.dao.jpa.Repository_Product;

/**
 *
 */
@Service
public class Service_ProductImpl_Generate
	implements Service_Product_Generate
{

	
	@org.springframework.beans.factory.annotation.Autowired
	private Repository_Product dao;

	@org.springframework.beans.factory.annotation.Autowired
	private bairui.international.service.Service_ProductRollImage service_ProductRollImage;

	@org.springframework.beans.factory.annotation.Autowired
	private bairui.international.service.Service_ProductOrderItem service_ProductOrderItem;

	@org.springframework.beans.factory.annotation.Autowired
	private bairui.international.service.Service_IndexModuleProduct service_IndexModuleProduct;



	
	
	
	/**
	 * deleteById
	 */
	public void deleteById(
		@com.sh_lianjing.annotation.ParameterName("id") @lombok.NonNull Long id
	) throws Exception {
		TB_Product bean = getDao().findById(id).get();
		// productRollImages
		java.util.List<bairui.international.model.domain.jpa.TB_ProductRollImage> productRollImages = service_ProductRollImage.page(it->it.product.eq(bean), org.springframework.data.domain.PageRequest.of(0, 3)).getContent();
		
		if(!productRollImages.isEmpty()){
			String str = "("+bean.toString()+")正在被("+bairui.international.model.domain.jpa.TTB_ProductRollImage.Comment+":[";
			boolean startFlag = true;
			for(bairui.international.model.domain.jpa.TB_ProductRollImage item : productRollImages){
				if(!startFlag){
					str += ", ";
				}
				startFlag = false;
				str += item.toString();
			}
			str += ", ...])使用";
			throw new com.lianjing.sh.validate.spring.exception.ValidateObjectException("", "productRollImages", str);
		}
		// productOrderItems
		java.util.List<bairui.international.model.domain.jpa.TB_ProductOrderItem> productOrderItems = service_ProductOrderItem.page(it->it.product.eq(bean), org.springframework.data.domain.PageRequest.of(0, 3)).getContent();
		
		if(!productOrderItems.isEmpty()){
			String str = "("+bean.toString()+")正在被("+bairui.international.model.domain.jpa.TTB_ProductOrderItem.Comment+":[";
			boolean startFlag = true;
			for(bairui.international.model.domain.jpa.TB_ProductOrderItem item : productOrderItems){
				if(!startFlag){
					str += ", ";
				}
				startFlag = false;
				str += item.toString();
			}
			str += ", ...])使用";
			throw new com.lianjing.sh.validate.spring.exception.ValidateObjectException("", "productOrderItems", str);
		}
		// indexModuleProducts
		java.util.List<bairui.international.model.domain.jpa.TB_IndexModuleProduct> indexModuleProducts = service_IndexModuleProduct.page(it->it.product.eq(bean), org.springframework.data.domain.PageRequest.of(0, 3)).getContent();
		
		if(!indexModuleProducts.isEmpty()){
			String str = "("+bean.toString()+")正在被("+bairui.international.model.domain.jpa.TTB_IndexModuleProduct.Comment+":[";
			boolean startFlag = true;
			for(bairui.international.model.domain.jpa.TB_IndexModuleProduct item : indexModuleProducts){
				if(!startFlag){
					str += ", ";
				}
				startFlag = false;
				str += item.toString();
			}
			str += ", ...])使用";
			throw new com.lianjing.sh.validate.spring.exception.ValidateObjectException("", "indexModuleProducts", str);
		}
		getDao().deleteById(id);
	}
	/**
	 * findDeleteById
	 */
	public TB_Product findDeleteById(
		@com.sh_lianjing.annotation.ParameterName("id") @lombok.NonNull Long id
	) throws Exception {
		TB_Product bean = getDao().findById(id).get();
		// productRollImages
		java.util.List<bairui.international.model.domain.jpa.TB_ProductRollImage> productRollImages = service_ProductRollImage.page(it->it.product.eq(bean), org.springframework.data.domain.PageRequest.of(0, 3)).getContent();
		
		if(!productRollImages.isEmpty()){
			String str = "("+bean.toString()+")正在被("+bairui.international.model.domain.jpa.TTB_ProductRollImage.Comment+":[";
			boolean startFlag = true;
			for(bairui.international.model.domain.jpa.TB_ProductRollImage item : productRollImages){
				if(!startFlag){
					str += ", ";
				}
				startFlag = false;
				str += item.toString();
			}
			str += ", ...])使用";
			throw new com.lianjing.sh.validate.spring.exception.ValidateObjectException("", "productRollImages", str);
		}
		// productOrderItems
		java.util.List<bairui.international.model.domain.jpa.TB_ProductOrderItem> productOrderItems = service_ProductOrderItem.page(it->it.product.eq(bean), org.springframework.data.domain.PageRequest.of(0, 3)).getContent();
		
		if(!productOrderItems.isEmpty()){
			String str = "("+bean.toString()+")正在被("+bairui.international.model.domain.jpa.TTB_ProductOrderItem.Comment+":[";
			boolean startFlag = true;
			for(bairui.international.model.domain.jpa.TB_ProductOrderItem item : productOrderItems){
				if(!startFlag){
					str += ", ";
				}
				startFlag = false;
				str += item.toString();
			}
			str += ", ...])使用";
			throw new com.lianjing.sh.validate.spring.exception.ValidateObjectException("", "productOrderItems", str);
		}
		// indexModuleProducts
		java.util.List<bairui.international.model.domain.jpa.TB_IndexModuleProduct> indexModuleProducts = service_IndexModuleProduct.page(it->it.product.eq(bean), org.springframework.data.domain.PageRequest.of(0, 3)).getContent();
		
		if(!indexModuleProducts.isEmpty()){
			String str = "("+bean.toString()+")正在被("+bairui.international.model.domain.jpa.TTB_IndexModuleProduct.Comment+":[";
			boolean startFlag = true;
			for(bairui.international.model.domain.jpa.TB_IndexModuleProduct item : indexModuleProducts){
				if(!startFlag){
					str += ", ";
				}
				startFlag = false;
				str += item.toString();
			}
			str += ", ...])使用";
			throw new com.lianjing.sh.validate.spring.exception.ValidateObjectException("", "indexModuleProducts", str);
		}
		getDao().deleteById(id);
		return bean;
	}
	/**
	 * deleteByIds
	 */
	public void deleteByIds(
		@com.sh_lianjing.annotation.ParameterName("ids") @lombok.NonNull Long ... ids
	) throws Exception {
		deleteByIds(java.util.Arrays.asList(ids));
	}
	
	/**
	 * deleteByIds
	 */
	public void deleteByIds(
		@com.sh_lianjing.annotation.ParameterName("ids") @lombok.NonNull java.util.List<Long> ids
	) throws Exception {
		for(Long id : ids){
			deleteById(id);
		}
	}
		






	/**
	 * getDao()
	 */
	public bairui.international.dao.jpa.Repository_Product getDao() {
		return dao;
	}

}
